<template>
    <div>
        <cjcNav title="建议详情" @customRouter="customRouter" />
        <!-- 进度条 -->
        <stuSprogress :EventList="this.$store.state.student.getEventByEventId" />
        <br>
        <!-- 列表展示 -->
        <stuLsitShow :EventList="this.$store.state.student.getEventByEventId"/>
        <br>
        <!-- 处理情况 -->
        <stuHandling :EventList="this.$store.state.student.getEventByEventId" @appraise="appraise"/>
        <div>
            <div :class="{Shadow: isMark}"></div>
            <div class="appraiseBox" :class="{markDown: isMark}">
                <div class="appraise-head">
                    <div class="appraise-Name">评价</div>
                    <div class="appraise-quit" @click="close">×</div>  
                </div>
                <div class="appraise-con" v-if="complete === true">
                    <div class="appraise-sel">
                        <div class="appraise-sel-item" 
                            v-for="(item, $index) in appraiseList"
                            :key="item.quicktype"
                            @click="selectAppraise(item)" 
                            :class="{active: activeIndex === $index}"
                            >
                            <img class="appraise-img" :src="item.img">
                            <div class="appraise-sel-txt">{{item.appraiseTxt}}</div>
                        </div>
                    </div>
                    <div class="appraise-content">
                        <Input v-model="appraiseContent" type="textarea" :rows="6" placeholder="请输入评价内容..." :maxlength="200"></Input>
                    </div>
                    <div class="appraise-btn" @click="isNull">提交</div>
                </div>

                <div class="appraise-con" v-if="completeSuccess === true">
                    <div>
                    <img class="appraise-img2" src="static/student/pjsuccess.png">
                    <div class="appraise-notice">评价成功</div>
                    </div>
                </div>
                <div class="appraise-con" v-if="completeFailed === true">
                    <div>
                    <img class="appraise-img2" src="static/student/pjfailed.png">
                    <div class="appraise-notice">评价失败</div>
                    </div>
                </div> 

            </div> 
        </div>
        <Spin size="large" fix v-if="landing"></Spin>
    </div>
</template>

<script>
export default {
    components: {
        cjcNav: () => import('@/components/common/Nav.vue'),
        stuSprogress: () => import('@/components/student/stuSprogress.vue'),
        stuLsitShow: () => import('@/components/student/stuLsitShow.vue'),
        stuHandling: () => import('@/components/student/stuHandling.vue'),
    },
    data() {
        return {
            landing: false,
            activeIndex: null,
            appraiseType: null,
            event_id: null,
            EventList: null,
            isMark: false,
            complete: true,
            appraiseContent: null,
            completeSuccess: false,
            completeFailed: false,
            appraiseList: [
                {
                    img: 'static/student/bestpj.png',
                    appraiseTxt: '优',
                    quicktype: 1,
                },
                {
                    img: 'static/student/goodpj.png',
                    appraiseTxt: '良',
                    quicktype: 2,
                },
                {
                    img: 'static/student/badpj.png',
                    appraiseTxt: '差',
                    quicktype: 3,
                }
            ]
        }
    },
    // watch: {
    //     '$store.state.student.getEventByEventId'() {
    //         this.EventList = this.$store.state.student.getEventByEventId
    //     }
    // },
    methods: {
        customRouter() {
            this.$router.push({
                name: 'stuHome'
            })
        },
        appraise() {
            this.isMark = true
            this.complete = true
        },
        close() {
            const Vm = this
            const State = this.$store.state
            Vm.isMark = false
            // this.complete = false
            // this.completeSuccess = false
            // this.completeFailed = false
            /**
             *  设置建议流列表
             */
            Vm.event_id = sessionStorage.getItem('stuEventId')
            async function setEvent() {
                // alert(123)
                let EventList = await Vm.$store.dispatch('getEventByEventId', {
                    userId: State.userInfo.USER_ID,
                    event_id: Vm.event_id
                })
                console.log(EventList)
                if (EventList.status === 0) {
                    Vm.$store.commit('SET_getEventByEventId', EventList.result)
                } else {
                    Vm.$store.commit('SET_getEventByEventId', 'noData')
                    Vm.$Message.error(EventList.msg)
                }
            }
            setEvent()
        },
        selectAppraise(item) {
            this.activeIndex = item.quicktype - 1
            console.log(item.quicktype)
            // console.log(item.quicktype)
            this.appraiseType = item.quicktype
        },
        isNull() {
            if (this.appraiseType === null || this.appraiseContent === null) {
                this.$Message.error('请填写完整评价！')
            } else {
                this.submitThumbsup()
            }
        },
        submitThumbsup() {
            const Vm = this
            const State = this.$store.state
            /**
             *  设置建议流列表
             */
            // console.log(State.userInfo.USER_ID)
            // console.log(Vm.event_id)
            // console.log(Vm.appraiseType)
            // console.log(Vm.appraiseContent)
            async function setAddComment() {
                let addCom = await Vm.$store.dispatch('addComment', {
                    user_id: State.userInfo.USER_ID,
                    event_id: Vm.event_id,
                    quiketype: Vm.appraiseType,
                    comment_content: Vm.appraiseContent
                })
                console.log(addCom.data.status)
                if (addCom.data.status === 0) {
                    Vm.$store.commit('SET_addComment', addCom.data.result)
                    Vm.completeSuccess = true
                    // Vm.completeFailed = false
                    Vm.complete = false
                    // Vm.$router.push({
                    //     name: 'stuHome'
                    // })
                } else {
                    // alert(123)
                    Vm.$store.commit('SET_addComment', 'noData')
                    // alert(123)
                    Vm.$Message.error(addCom.data.msg)
                    Vm.completeFailed = true
                    console.log(Vm.completeFailed)
                    // Vm.completeSuccess = false
                    Vm.complete = false
                }
            }
            setAddComment()
        },
        /**
         *  再次调用建议流列表
         */
        async setEventAgain() {
            let EventList = await this.$store.dispatch('getEventByEventId', {
                userId: this.$store.state.userInfo.USER_ID,
                event_id: this.event_id
            })
            // console.log(EventList)
            if (EventList.status === 0) {
                this.$store.commit('SET_getEventByEventId', EventList.result)
            } else {
                this.$store.commit('SET_getEventByEventId', 'noData')
                this.$Message.error(EventList.msg)
            }
        }
    },
    created() {
        const Vm = this
        const State = this.$store.state
        Vm.landing = true
        /**
         * 确认用户信息是否加载
         */
        function isUserInfo() {
            return new Promise((resolve, reject) => {
                let isu = setInterval(() => {
                    if (Vm.$store.state.userInfo) {
                        clearInterval(isu)
                        resolve()
                    }
                }, 100)
            })
        }
        /**
         *  设置建议流列表
         */
        Vm.event_id = sessionStorage.getItem('stuEventId')
        async function setEvent() {
            // alert(123)
            let EventList = await Vm.$store.dispatch('getEventByEventId', {
                userId: State.userInfo.USER_ID,
                event_id: Vm.event_id
            })
            console.log(EventList)
            Vm.landing = false
            if (EventList.status === 0) {
                Vm.$store.commit('SET_getEventByEventId', EventList.result)
            } else {
                Vm.$store.commit('SET_getEventByEventId', 'noData')
                Vm.$Message.error(EventList.msg)
            }
        }
        async function Step() {
            setEvent()
        }
        isUserInfo().then(() => {
            Step()
        })
    }
}
</script>

<style lang="less">
.Shadow {
    position: fixed; 
    /* display: flex; */
    z-index: 10; 
    bottom: 0;
    /* align-items: flex-end; */
    background-color: rgba(0,0,0,.4);
    width: 100%;
    height: 100vh; 
}
.markDown {
  transform:translateY(-415px);
}
.appraiseBox {
  background-color: #fff;
  width: 100%;
  height: 415px;
  position: fixed;
  overflow: hidden;
  bottom: -415px;
   z-index: 11; 
  transition: all .3s linear 0s;
  -webkit-transition: all .3s linear 0s; 
}

.appraise-head {
  height: 50px;
  width: 100%;
  padding: 10px;
  border-bottom: 1px solid #eee;
  /* text-align: center; */
  display: flex;
  align-items: center;   
  justify-content: center;    
}
.appraise-Name {
  font-size: 16px;
  font-weight: bold;
  
  color: #232323;
}
.appraise-quit {
  position: absolute;
  right:0;
  font-size: 30px;
  height: 40px;
  width: 40px;
  color: #0093dd;
  display: flex; 
  align-items: center;    
  justify-content: center;  
   /* background-color: #eeeeee;  */
}
.appraise-con {
  display: flex;
  flex-direction: column;
  align-items: center;   
  justify-content: center; 
  padding: 20px 40px;
}
.appraise-sel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin: 0 0 10px;
}
.appraise-sel-item {
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;   
    justify-content: center;
    
    border-radius: 5px;
}
.active {
    border: 1px dashed #0093dd;
    color: #0093dd;
}
.appraise-sel-txt {
    margin: 5px 0;
    font-size: 14px; 
}
.appraise-content {
    width: 100%;

}
.appraise-img {
  height: 50px;
//   margin:10px 0;
}
.appraise-img2 {
  margin-top:60px; 
  height: 100px;
  display: flex;
  align-items: center;   
  justify-content: center; 
} 
.appraise-notice {
  text-align: center;
  margin: 10px;
  color: #999999;
  font-size: 14px;
}
.appraise-appraise {
  text-align: center;
  margin: 5px 0 10px;
  color: #0093dd;
  font-size: 14px;
}

.appraise-btn {
  height: 40px;
  width: 86%;
  margin: 20px 0;
  font-size: 16px;
  background-color: #0093dd;
  color: #fff;
  display: flex;
  align-items: center;   
  justify-content: center;
  border-radius: 5px;
}
</style>
